package com.linwen.javase.desgin_pattern.BigTalkDesignPattenJAVACode._17单例模式._3基本代码;

//单例模式类
class Singleton {

    private volatile static Singleton instance;

    //构造方法private化
    private Singleton() {
    }

    //得到Singleton的实例（唯一途径）  双重判断，并使用volatile  保证可见性
    public static Singleton getInstance() {
        if (instance == null){
            synchronized(Singleton.class){
                if (instance == null){
                    instance = new Singleton();
                }
            }
        }
        return instance;
    }
}
